<?php include "../public/header.php";?>
<?php include "../public/header_show.php";?>
<style>
    .tableShow .layui-table-body{max-height: 350px}
    div.layui-table-cell{height: auto!important;overflow:visible;text-overflow:inherit;white-space:normal;line-height: 24px!important;}
</style>
<body id="xiangqingPage">
<div id="xiangqingBox" style="padding-bottom: 10px">
    <div class="page-title">
        <div class="page-title-con">
            <span>复用</span>
            <div class="move_title"></div>
            <div class="page-title-opt-list">
                <button type="button" class="layui-btn layui-btn-sm btn-dark marginr5" lay-submit="" key="1" lay-filter="add">覆盖</button>
                <button type="button" class="layui-btn layui-btn-sm btn-dark marginr5" lay-submit="" key="2" lay-filter="add">附加</button>
                <span id="page-close" class="page-close" onclick="layer_close()"><i class="layui-icon layui-icon-close"></i></span>
            </div>
        </div>
    </div>
    <form class="main-container layui-form layui-form-pane">
        <div class="table-box tablenes">
            <script type="text/html" id="toolbarDemo">组价清单</script>
            <div class="tableShow">
                <table id="datalist" lay-filter="datalist"></table>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-row layui-col-space10">
                <div class="layui-col-md12">
                    <label class="layui-form-label" style="text-align: left;padding: 10px 0;width: 80px"><b>复用条件：</b></label>
                    <div class="layui-input-block" style="margin-left: 0!important;">
                        <div class="radio-block">
                            <input type="checkbox" id="is_fenname" lay-filter="tongchk" lay-skin="primary" title="分部名称" checked>
                            <input type="checkbox" id="is_encode" lay-filter="tongchk" lay-skin="primary" title="项目编码">
                            <input type="checkbox" id="is_enname" lay-filter="tongchk" lay-skin="primary" title="项目名称">
                            <input type="checkbox" id="is_enfeat" lay-filter="tongchk" lay-skin="primary" title="项目特征描述">
                            <input type="checkbox" id="is_enunit" lay-filter="tongchk" lay-skin="primary" title="计量单位">
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="table-box tablenes">
            <script type="text/html" id="toolbarDemo_tong">待复用数据</script>
            <div class="tableShow">
                <table id="datalist_tong" lay-filter="datalist_tong"></table>
            </div>
        </div>
    </div>
</div>
<script>
    var param_id = getQueryVariable('id') || 0;

    layui.use(['form', 'layer', "laytp",'element','dropdown','laypage','table','soulTable'], function() {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable,element = layui.element, layer = layui.layer;
        get_data();

        function get_data(){
            var is_fenname = $("#is_fenname").prop('checked') ? 1 : 0;
            var is_encode = $("#is_encode").prop('checked') ? 1 : 0;
            var is_enname = $("#is_enname").prop('checked') ? 1 : 0;
            var is_enfeat = $("#is_enfeat").prop('checked') ? 1 : 0;
            var is_enunit = $("#is_enunit").prop('checked') ? 1 : 0;

            if(is_fenname< 1 && is_encode< 1 && is_enname< 1 && is_enfeat< 1 && is_enunit< 1){
                // is_enname = 1;
                // $("#is_enname").prop('checked', true);
                render_from();
            }


            facade.ajax({type: 'get', url: ask_main_basallist_tplex, data:{
                id: param_id, is_fenname: is_fenname, is_encode: is_encode, is_enname: is_enname, is_enfeat: is_enfeat, is_enunit: is_enunit,
            }}).done(function(res){
                if (res.code === 2000) {
                    var data = res.data.data;

                    var mytableList = table.render({
                        elem: "#datalist",data:res.data.list, toolbar: '#toolbarDemo', page: false
                        ,limit:TabInitShow.limit,soulSort: TabInitShow.soulSort,method: TabInitShow.method, overflow: TabInitShow.overflow
                        ,defaultToolbar: ['','',''],filter: TabInitShow.filter ,text: TabInitShow.text
                        ,request: TabInitShow.request,response: TabInitShow.response,contextmenu:get_table_contextmenu(soulTable)
                        , cols: [[
                            {type: 'checkbox', LAY_CHECKED: true}
                            ,{type:'numbers',title:'序号'}
                            ,{field:'type_name',title:'费用类型'}
                            ,{field:'basetype',title:'类别'}
                            ,{field:'name',title:'名称'}
                            ,{field:'guige',title:'特征描述',minWidth:200}
                            ,{field:'valunit',title:'单位',width:90}
                            ,{field:'content',title:'含量'}
                            ,{field:'loss_rate',title:'损耗率'}
                            ,{field:'no_price',title:'不含税单价(元)'}
                            ,{field:'price',title:'成本单价(元)'}
                        ]]
                        , done: function (res) {
                            soulTable.render(this);
                        }
                    });

                    var tongtableList = table.render({
                        elem: "#datalist_tong",data:res.data.tonglist, toolbar: '#toolbarDemo_tong', page: false
                        ,limit:TabInitShow.limit,soulSort: TabInitShow.soulSort,method: TabInitShow.method, overflow: TabInitShow.overflow
                        ,defaultToolbar: ['','',''],filter: TabInitShow.filter ,text: TabInitShow.text
                        ,request: TabInitShow.request,response: TabInitShow.response,contextmenu:get_table_contextmenu(soulTable)
                        , cols: [[
                            {type: 'checkbox'}
                            ,{type:'numbers',title:'序号'}
                            ,{field:'fenname',title:'分部名称'}
                            ,{field:'encode',title:'项目编码'}
                            ,{field:'enname',title:'项目名称'}
                            ,{field:'enfeat',title:'项目特征描述',minWidth:200}
                            ,{field:'enunit',title:'计量单位',width:90}
                            ,{field:'enword',title:'工程量'}
                            ,{field:'price',title:'综合成本单价'}
                        ]]
                        , done: function (res) {
                            soulTable.render(this);
                        }
                    });


                    render_from();
                }
            });
        }


        form.on('checkbox(tongchk)', function(data){
            get_data();
        });


        form.on('submit(add)', function(data){
            var types = $(this).attr('key') || '';
            var yuanlist = layui.table.checkStatus('datalist').data
            var tonglist = layui.table.checkStatus('datalist_tong').data
            if(yuanlist.length < 1){
                facade.error('请选择原数据');return false;
            }
            if(tonglist.length < 1){
                facade.error('请选择被覆盖数据');return false;
            }

            data.field.id = param_id;
            data.field.types = types;
            data.field.yuanlist = yuanlist;
            data.field.tonglist = tonglist;

            facade.ajax({url: ask_main_basallist_tplex, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    parent.window.location.reload();
                }
            });

            return false;
        });

    });




    function get_table_check_idarr(datalist='datalist') {
        var checkStatus = layui.table.checkStatus(datalist).data;
        var ids = [];
        for(var i=0;i<checkStatus.length;i++){
            ids.push(checkStatus[i].id)
        }
        return ids;
    }

</script>
</body>
</html>




